<?php

function generateOptions($ProfileEdit) {
    if( empty($ProfileEdit) ) {
        return false;
    }
    $ArProfile = Dracosys::getSessionValue(SESSION_INTERFACE, 'ProfileList');
    $option = '<option value="">Selecione um Perfil</option>';
    foreach ($ArProfile as $Profile) {
        if( !$Profile->equals($ProfileEdit) ) {
            $option .= '<option value="' . $Profile->getIDPerfil() . '">' . $Profile->getStPerfil() . '</option>';
        }
    }
    return $option;
}


$ArUsers = Dracosys::getSessionValue(SESSION_INTERFACE, 'UserList');
$Profile = Dracosys::getSessionValue(SESSION_INTERFACE, 'ProfileEdit');

$options = generateOptions($Profile);

?>
<h2>Deletar Perfil</h2>
<section id="DeleteProfile">
    <form method="post" action="perfil/delete" name="FormDeletePerfil">
        <section id="DeleteProfile_Dados" class="section-update">
            <?php if (!empty($Profile)): ?>
                <div class="unique">O Setor "<strong><?= $Profile->getStPerfil() ?></strong>" está prestes a ser deletado.</div>
                    <?php if( !empty($ArUsers) ): ?>
                        <div class="unique">Porém existem Usuários que não podem ser excluídos, você deverá declarar novos perfis.</div>
                        <table class="deleteTable">
                            <thead>
                                <tr>
                                    <th class="name">Nome</th>
                                    <th class="email">Email</th>
                                    <th class="changeSector">Trocar Perfil</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($ArUsers as $User): ?>
                                    <tr>
                                        <td><?= $User->getArDadosUsuario('StNome') ?></td>
                                        <td><?= $User->getArDadosUsuario('StEmail') ?></td>
                                        <td>
                                            <select name="IDNewPerfil<?= $User->getIdUsuario() ?>" id="DeleteProfile_IDNewPerfil<?= $User->getIdUsuario() ?>">
                                                <?= $options ?>
                                            </select>
                                        </td>
                                    </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
                <div class="btn"><button class="v2">Confirmar</button></div>
                <input type="hidden" name="IDPerfil" value="<?= treatUrl('id') ?>" id="DeleteProfile_IDPerfil" />
            <?php else:  ?>
                <section id="Messages">
                      <p class="Error">O perfil com identificador <?= treatUrl('id') ?> não existe.</p>
                </section>
            <?php endif; ?>
        </section>
    </form>
</section>